#!/usr/local/bin/python3
# -*- coding:utf8 -*-
# Author Aaron 
# 2017-03-31 22:46:05
# 共阳数码管
import RPi.GPIO as GPIO
import time

GPIO.setwarnings(False)
global xxxxx
xxxxx = 0
switch = 7

led1 = 32
led2 = 36
led3 = 38
led4 = 40
led5 = 37
led6 = 35
led7 = 33
led8 = 31
GPIO.setmode(GPIO.BOARD)
GPIO.setup(switch, GPIO.IN)
GPIO.setup(led1, GPIO.OUT)
GPIO.setup(led2, GPIO.OUT)
GPIO.setup(led3, GPIO.OUT)
GPIO.setup(led4, GPIO.OUT)
GPIO.setup(led5, GPIO.OUT)
GPIO.setup(led6, GPIO.OUT)
GPIO.setup(led7, GPIO.OUT)
GPIO.setup(led8, GPIO.OUT)


def excute(values):
    GPIO.output(led1, values[0])
    GPIO.output(led2, values[1])
    GPIO.output(led3, values[2])
    GPIO.output(led4, values[3])
    GPIO.output(led5, values[4])
    GPIO.output(led6, values[5])
    GPIO.output(led7, values[6])
    GPIO.output(led8, values[7])


def reset():
    print("reset")
    excute([1, 1, 1, 1, 1, 1, 1, 1])


def test():
    print("test")
    excute([0, 0, 0, 0, 0, 0, 0, 0])


def point():
    print("point")
    excute([1, 1, 1, 0, 1, 1, 1, 1])


def show0():
    print("0")
    excute([0, 0, 0, 1, 0, 0, 0, 1])


def show1():
    print("1")
    excute([1, 1, 0, 1, 0, 1, 1, 1])


def show2():
    print("2")
    excute([0, 0, 1, 1, 0, 0, 1, 0])


def show3():
    print("3")
    excute([1, 0, 0, 1, 0, 0, 1, 0])


def show4():
    print("4")
    excute([1, 1, 0, 1, 0, 1, 0, 0])


def show5():
    print("5")
    excute([1, 0, 0, 1, 1, 0, 0, 0])


def show6():
    print("6")
    excute([0, 0, 0, 1, 1, 0, 0, 0])


def show7():
    print("7")
    excute([1, 1, 0, 1, 0, 0, 1, 1])


def show8():
    print("8")
    excute([0, 0, 0, 1, 0, 0, 0, 0])


def show9():
    print("9")
    excute([1, 0, 0, 1, 0, 0, 0, 0])


reset()
time.sleep(1)
test()
time.sleep(1)
while True:
    if GPIO.input(switch):
        global xxxxx
        if xxxxx == 0:
            show0()

        if xxxxx == 1:
            show1()
        if xxxxx == 2:
            show2()

        if xxxxx == 3:
            show3()

        if xxxxx == 4:
            show4()

        if xxxxx == 5:
            show5()

        if xxxxx == 6:
            show6()
        if xxxxx == 7:
            show7()

        if xxxxx == 8:
            show8()
        if xxxxx == 9:
            show9()
        if xxxxx == 10:
            point()
        if xxxxx == 11:
            show0()
            xxxxx = 0
        xxxxx += 1
        time.sleep(0.3)
GPIO.cleanup()
